package com.webserver.core;

import com.webserver.http.HttpContext;
import com.webserver.http.HttpServletRequest;
import com.webserver.http.HttpServletResponse;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 用来完成处理请求的环节
 */

public class DispatcherServlet {
    public void service(HttpServletRequest request, HttpServletResponse response) {
        String path = request.getUri();

        System.out.println("抽象路径:" + path);
        File file = new File("./webapps/" + path);


        if (file.isFile()) {
            response.setContentFile(file);
        } else {
            response.setStatusCode(404);
            response.setStatusReason("Not Found");
            file = new File("./webapps/root/404.html");
            response.setContentFile(file);
        }

        response.addHeader("Server", "WebServer");

    }
}
